<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      const goodsList = [
        {
          id: '4001172',
          name: '张三',
          price: 289.9,
          count: 2,
          spec: { color: '白色' },
        },
        {
          id: '4001009',
          name: '李四',
          price: 109.8,
          count: 3,
          spec: { size: '40cm*40cm', color: '黑色' },
        },
        {
          id: '4001874',
          name: '老六',
          price: 488,
          count: 1,
          spec: { color: '青色', sum: '一大四小' },
        },
        {
          id: '4001649',
          name: '老六',
          price: 139,
          count: 1,
          spec: { size: '小号', color: '紫色' },
          gift: '50g茶叶,清洗球,宝马, 奔驰',
        },
      ]

      // 封装函数 找到老六这个对象 返回整个对象出来
      // const arr = goodsList.find((item) => {
      //   const { name, price } = item
      //   return item.name === '老六'
      // })
      // console.log(arr)
      // 封装函数 找到老六这俩项 筛选出来

      // const res = goodsList.filter(function (item) {
      //   const { name, price } = item
      //   return item.name === '老六'
      // })

      //  console.log(res)

      // 封装函数 把所有的价格累加
     
   const re = goodsList.reduce(function(prev,item) {
    // console.log(item.price);
   return  prev+=item.price
   },0)
      console.log(re);
      // 数组对象解构出来

      goodsList.forEach((item) => {
        const { id, name, price, count, spec } = item
        // console.log(id,name,price,count,spec)
      })
    </script>
  </body>
</html>
